# Makefile

OBJS	= parser.o lexer.o main.o Schema.o QueryStructures.o ExprInfo.o TableScan.o DirectoryPage.o DataPage.o Tuple.o DirHeader.o ParseUtil.o DiskManager.o SysCatalog.o Heap.o FileHandler.o FreePageLinkedList.o BufferManager.o Frame.o DBMetaData.o ReplacementPolicy.o MemoryTest.o BufferUtility.o BufferTest.o MemoryManagement.o BaseEntity.o PageHeader.o  PostFixEvaluator.o Delete.o CreateTable.o GeneralPageHeaderAccessor.o SqlEditor.o QueryDispatcher.o CreateDatabase.o BMEditor.o IndexEditor.o BPlusTree.o BPlusTreeLeafNode.o BPlusTreeNode.o IndexHeaderPage.o ShowDatabases.o OpenDatabase.o ShowTables.o Validation.o DescribeTable.o Timer.o InsertTable.o SelectTable.o

CC	= g++

CFLAGS	= -g -Wall -ansi -pedantic

TARGET = RI3DB.exe

################# Final exe

#ri3db:	$(OBJS)
#		$(CC) $(CFLAGS) $(OBJS) -o ri3db -ly -ll

$(TARGET): $(OBJS)
	$(CXX) -o  $(TARGET) $(OBJS) $(LIBS)
all:	$(TARGET)

#################

################# Main()

#main.o : Main.cpp
#   		$(CC) $(CFLAGS) -c Main.cpp -o main.o
main.o:	 Main.cpp
		$(CC) $(CFLAGS) -c Main.cpp -o main.o

#main.o :
################# Buffer Mngr

BufferManager.o: BufferManager/BufferManager.cpp
		$(CC) $(CFLAGS) -c BufferManager/BufferManager.cpp -o BufferManager.o
		
BufferUtility.o: BufferManager/BufferUtility.cpp
		$(CC) $(CFLAGS) -c BufferManager/BufferUtility.cpp -o BufferUtility.o

Frame.o: BufferManager/Frame.cpp
		$(CC) $(CFLAGS) -c BufferManager/Frame.cpp -o Frame.o
		
ReplacementPolicy.o: BufferManager/ReplacementPolicy.cpp
		$(CC) $(CFLAGS) -c BufferManager/ReplacementPolicy.cpp -o ReplacementPolicy.o		


################# SQL
CreateTable.o: sql/CreateTable.cpp
		$(CC) $(CFLAGS) -c sql/CreateTable.cpp -o CreateTable.o

Delete.o: sql/Delete.cpp
		$(CC) $(CFLAGS) -c sql/Delete.cpp -o Delete.o

PostFixEvaluator.o: sql/PostFixEvaluator.cpp
		$(CC) $(CFLAGS) -c sql/PostFixEvaluator.cpp -o PostFixEvaluator.o

TableScan.o: sql/TableScan.cpp
		$(CC) $(CFLAGS) -c sql/TableScan.cpp -o TableScan.o


QueryDispatcher.o: sql/QueryDispatcher.cpp
		$(CC) $(CFLAGS) -c sql/QueryDispatcher.cpp -o QueryDispatcher.o

CreateDatabase.o: sql/CreateDatabase.cpp
		$(CC) $(CFLAGS) -c sql/CreateDatabase.cpp -o CreateDatabase.o

ShowDatabases.o: sql/ShowDatabases.cpp
		$(CC) $(CFLAGS) -c sql/ShowDatabases.cpp -o ShowDatabases.o

OpenDatabase.o: sql/OpenDatabase.cpp
		$(CC) $(CFLAGS) -c sql/OpenDatabase.cpp -o OpenDatabase.o

ShowTables.o: sql/ShowTables.cpp
		$(CC) $(CFLAGS) -c sql/ShowTables.cpp -o ShowTables.o

Validation.o: sql/Validation.cpp
		$(CC) $(CFLAGS) -c sql/Validation.cpp -o Validation.o

DescribeTable.o: sql/DescribeTable.cpp
		$(CC) $(CFLAGS) -c sql/DescribeTable.cpp -o DescribeTable.o

InsertTable.o: sql/InsertTable.cpp
		$(CC) $(CFLAGS) -c sql/InsertTable.cpp -o InsertTable.o

SelectTable.o: sql/SelectTable.cpp
		$(CC) $(CFLAGS) -c sql/SelectTable.cpp -o SelectTable.o


################# Page Layout
DirectoryPage.o: PageLayout/DirectoryPage.cpp
		$(CC) $(CFLAGS) -c PageLayout/DirectoryPage.cpp -o DirectoryPage.o
		
DirHeader.o: PageLayout/DirHeader.cpp
		$(CC) $(CFLAGS) -c PageLayout/DirHeader.cpp -o DirHeader.o
		
Heap.o: PageLayout/Heap.cpp
		$(CC) $(CFLAGS) -c PageLayout/Heap.cpp -o Heap.o
	
DataPage.o: PageLayout/DataPage.cpp
		$(CC) $(CFLAGS) -c PageLayout/DataPage.cpp -o DataPage.o

Tuple.o: PageLayout/Tuple.cpp
		$(CC) $(CFLAGS) -c PageLayout/Tuple.cpp -o Tuple.o
		
		
GeneralPageHeaderAccessor.o: PageLayout/GeneralPageHeaderAccessor.cpp
		$(CC) $(CFLAGS) -c PageLayout/GeneralPageHeaderAccessor.cpp -o GeneralPageHeaderAccessor.o		

DBMetaData.o: PageLayout/DBMetaData.cpp
		$(CC) $(CFLAGS) -c PageLayout/DBMetaData.cpp -o DBMetaData.o
		
FreePageLinkedList.o: PageLayout/FreePageLinkedList.cpp
		$(CC) $(CFLAGS) -c PageLayout/FreePageLinkedList.cpp -o FreePageLinkedList.o



################# Disk Manager
DiskManager.o: DiskManager/DiskManager.cpp
		$(CC) $(CFLAGS) -c DiskManager/DiskManager.cpp -o DiskManager.o


FileHandler.o: DiskManager/FileHandler.cpp
		$(CC) $(CFLAGS) -c DiskManager/FileHandler.cpp -o FileHandler.o


################# DBStore



################# Global

BaseEntity.o: Global/BaseEntity.cpp
		$(CC) $(CFLAGS) -c Global/BaseEntity.cpp -o BaseEntity.o

PageHeader.o: Global/PageHeader.cpp
		$(CC) $(CFLAGS) -c Global/PageHeader.cpp -o PageHeader.o
		

################# Index Mngr

BPlusTree.o: IndexManager/BPlusTree.cpp
		$(CC) $(CFLAGS) -c IndexManager/BPlusTree.cpp -o BPlusTree.o
		
BPlusTreeLeafNode.o: IndexManager/BPlusTreeLeafNode.cpp
		$(CC) $(CFLAGS) -c IndexManager/BPlusTreeLeafNode.cpp -o BPlusTreeLeafNode.o
		
BPlusTreeNode.o: IndexManager/BPlusTreeNode.cpp
		$(CC) $(CFLAGS) -c IndexManager/BPlusTreeNode.cpp -o BPlusTreeNode.o
		
IndexHeaderPage.o: IndexManager/IndexHeaderPage.cpp
		$(CC) $(CFLAGS) -c IndexManager/IndexHeaderPage.cpp -o IndexHeaderPage.o
		



################# UX Mngr

SqlEditor.o: UXManager/SqlEditor.cpp
		$(CC) $(CFLAGS) -c UXManager/SqlEditor.cpp -o SqlEditor.o
		
BMEditor.o: UXManager/BMEditor.cpp
		$(CC) $(CFLAGS) -c UXManager/BMEditor.cpp -o BMEditor.o

IndexEditor.o: UXManager/IndexEditor.cpp
		$(CC) $(CFLAGS) -c UXManager/IndexEditor.cpp -o IndexEditor.o

################# Log

################# Sysfiles
SysCatalog.o: Sysfiles/SysCatalog.cpp
		$(CC) $(CFLAGS) -c Sysfiles/SysCatalog.cpp -o SysCatalog.o


################# Test
MemoryTest.o: Test/MemoryTest.cpp
		$(CC) $(CFLAGS) -c Test/MemoryTest.cpp -o MemoryTest.o

BufferTest.o: Test/BufferTest.cpp
		$(CC) $(CFLAGS) -c Test/BufferTest.cpp -o BufferTest.o
################# Utils

MemoryManagement.o: Utils/MemoryManagement.cpp
		$(CC) $(CFLAGS) -c Utils/MemoryManagement.cpp -o MemoryManagement.o

Timer.o: Utils/Timer.cpp
		$(CC) $(CFLAGS) -c Utils/Timer.cpp -o Timer.o

		
################# Parser Code
lexer.o:	parser/lexer.c
		$(CC) $(CFLAGS) -c parser/lexer.c -o lexer.o

lexer.c:	parser/lexer.l 
		flex parser/lexer.l
		mv lex.yy.c lexer.c

parser.o:	parser/parser.c
		$(CC) $(CFLAGS) -c parser/parser.c -o parser.o

parser.c:	parser/parser.y
		bison -d -v parser/parser.y
		cp parser.tab.c parser.c
		cmp -s parser.tab.h tok.h || cp parser.tab.h tok.h

Schema.o:	Sysfiles/Schema.cpp
		$(CC) $(CFLAGS) -c Sysfiles/Schema.cpp -o Schema.o	

QueryStructures.o:	dependency/QueryStructures.cpp
		$(CC) $(CFLAGS) -c dependency/QueryStructures.cpp -o QueryStructures.o	
ExprInfo.o: dependency/ExprInfo.cpp		
		$(CC) $(CFLAGS) -c dependency/ExprInfo.cpp -o ExprInfo.o	

ParseUtil.o: parser/ParseUtil.cpp
		$(CC) $(CFLAGS) -c parser/ParseUtil.cpp -o ParseUtil.o


###This main for testing parser
#main.o:		parser/main.cc
#		$(CC) $(CFLAGS) -c parser/main.cc -o main.o
#

#lexer.o parser.o  : parser/heading.h
#lexer.o main.o		: parser/tok.h
#Schema.o		: dependency/Schema.h
#ExecuteStructures.o	: dependency/ExecuteStructures.h
#ExprInfo.o: dependency/ExprInfo.h
#ParseUtil.o: parser/ParseUtil.h

clean:
	rm -f *.o *~ lexer.c lex.yy.c parser.c tok.h parser.tab.c parser.tab.h parser.output RI3DB.exe 

